//
//  Chat.m
//  K-Music
//
//  Created by CHUN on 15/12/27.
//  Copyright © 2015年 CHUN. All rights reserved.
//

#import "Chat.h"
#import "WMPageController.h"
#import "MessageVC.h"
#import "Near_message.h"
#import "YYplayerVC.h"
#import "MessageView.h"
#import "Near_View.h"
#import "New_ChatRoomVC.h"

@interface Chat ()
{
    UIView *choruslineView;
    UIView *sololineView;
}
@property(strong,nonatomic)MessageView * message_View;
@property(strong,nonatomic)Near_View * near_View;


@end

@implementation Chat

- (void)viewDidAppear:(BOOL)animated
{
//    [self createUI];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"chat_icon" highIcon:@"chat_icon" target:self action:@selector(New_Chat_room)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"play" highIcon:@"play" target:self action:@selector(play_play)];
    
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, mainScreenWidth, 60)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    UISegmentedControl * segmentedCtr = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"消息列表", @"附近群组", nil]];
    segmentedCtr.frame = CGRectMake(0, 0, mainScreenWidth, 60);
    segmentedCtr.tintColor = [UIColor whiteColor];
    segmentedCtr.selectedSegmentIndex = 0;
    [segmentedCtr addTarget:self action:@selector(selectedSegmentIndexCount:) forControlEvents:(UIControlEventValueChanged)];
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor orangeColor]};
    [segmentedCtr setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor blackColor]};
    [segmentedCtr setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    [bgView addSubview:segmentedCtr];
    
    choruslineView = [[UIView alloc]initWithFrame:CGRectMake(mainScreenWidth/8.0, 50, mainScreenWidth/4.0, 2)];
    choruslineView.backgroundColor = [UIColor orangeColor];
    [bgView addSubview:choruslineView];
    
    sololineView = [[UIView alloc]initWithFrame:CGRectMake(mainScreenWidth/2.0+mainScreenWidth/8.0, 50, mainScreenWidth/4.0, 2)];
    sololineView.backgroundColor = [UIColor orangeColor];
    sololineView.hidden = YES;
    [bgView addSubview:sololineView];
    
    _message_View = [[MessageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(choruslineView.frame), mainScreenWidth, mainScreenHeight-227+49)superViewCtr:self];
    _message_View.hidden = NO;
    [self.view addSubview:_message_View];
    
    _near_View = [[Near_View alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(choruslineView.frame), mainScreenWidth, mainScreenHeight-227+49)superViewCtr:self];
    _near_View.hidden = YES;
    [self.view addSubview:_near_View];
    
    
}

-(void)selectedSegmentIndexCount:(UISegmentedControl *)sender
{
    if(sender.selectedSegmentIndex == 0)
    {
        choruslineView.hidden = NO;
        sololineView.hidden = YES;
        _message_View.hidden = NO;
        _near_View.hidden = YES;
    }
    else if(sender.selectedSegmentIndex ==1)
    {
        choruslineView.hidden = YES;
        sololineView.hidden = NO;
        _message_View.hidden = YES;
        _near_View.hidden = NO;
    }
}

- (void)New_Chat_room
{
    New_ChatRoomVC * chat = [[New_ChatRoomVC alloc]init];
    [self.navigationController pushViewController:chat animated:YES];
}







































- (void)createUI
{
    NSArray * viewControllers = @[[MessageVC class], [Near_message class]];
    
    NSArray *titles = @[@"消息列表", @"附近群组"];
    
    WMPageController *pageVC = [[WMPageController alloc] initWithViewControllerClasses:viewControllers andTheirTitles:titles];
    
    pageVC.pageAnimatable = YES;
    pageVC.menuItemWidth = 100;
    pageVC.menuHeight = 50;
    pageVC.titleSizeSelected = 15;
    pageVC.titleColorSelected = [UIColor orangeColor];
    pageVC.postNotification = YES;
    pageVC.bounces = YES;
    pageVC.menuBGColor = [UIColor whiteColor];
    
    // 下划线
    pageVC.title = @"畅聊";
    pageVC.menuViewStyle = WMMenuViewStyleLine;

    pageVC.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"chat_icon" highIcon:@"chat_more" target:self action:nil];
    pageVC.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"play" highIcon:@"play" target:self action:@selector(play_play)];

    [self.navigationController pushViewController:pageVC animated:NO];
}


- (void)play_play
{
    NSLog(@"play");
//    [MBProgressHUD showErrorWithStatus:@"播放器" toView:self.view];
    
    YYplayerVC* yy = [[YYplayerVC alloc]init];
    
    yy.hidesBottomBarWhenPushed = YES;
    
    yy.musicData= [User_information conversion].musicData[0];
    
    [yy setTracks:[Track remoteTracks]];
    
    [self.navigationController pushViewController:yy animated:NO];
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"music_play" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



@end
